const { sys_parameter, op } = require("../../middleware/baseModel");

module.exports = {
  "GET /sys_parameter/index": async (ctx, next) => {
    const resList = await sys_parameter.findAll({ where: { is_modified: 0 } });
    return ctx.success(resList);
  },

  "GET /sys_parameter/key": async (ctx, next) => {
    let key = ctx.get("key");
    const res = await sys_parameter.findOne({ where: { key: key } });
    return ctx.success(res);
  },

  "POST /sys_parameter/setSysConfig": async (ctx, next) => {
    let { title, logoUrl } = ctx.getBody();
    await sys_parameter.update({ value: title }, { where: { key: "sys_title" } });
    await sys_parameter.update({ value: logoUrl }, { where: { key: "sys_logo" } });
    return ctx.success();
  },

  "POST /sys_parameter/add": async (ctx, next) => {
    let row = ctx.getBody();
    const res = await sys_parameter.create(row);
    return ctx.success(res);
  },
  "POST /sys_parameter/edit": async (ctx, next) => {
    let row = ctx.getBody();
    let id = ctx.get("id");
    const resList = await sys_parameter.update(row, {
      where: {
        id: id,
      },
    });
    return ctx.success(resList);
  },
  "POST /sys_parameter/del": async (ctx, next) => {
    let id = ctx.get("id");
    const res = await sys_parameter.destroy({
      where: {
        id: id,
      },
    });
    return ctx.success(res);
  },
};
